/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package POJO;

import DB.TripManager;
import DB.ContentContainerManager;
import java.sql.Connection;

/**
 *
 * @author bram
 */
public class JavascriptHandler {

    public static void GetContent(int tripId, ContentObject coarray[], User user, Connection c) {
        /*if ((coarraysize = ccm.GetNumContentsForContainer(tripId)) > -1)
        coarray = new ContentObject[coarraysize];
        for (int i = 0; i < triparray.length; i++) {
        
        }*/
    }

    public static ContainerObject[] GetContainersForTrip(int tripID, User user, Connection c) {
        TripManager tm = new TripManager(c);
        ContentContainerManager ccm = new ContentContainerManager(c);
        int containerIDs[];
        ContainerObject[] result = null;

        if (user != null) {
            if (user.username != null) {
                if (tm.isOwnerOf(tripID, user.username)) {
                    containerIDs = ccm.getAllContentContainersOfTripForOwners(tripID);
                } else if (tm.isFamilyOf(tripID, user.username)) {
                    containerIDs = ccm.getAllContentContainersOfTripForFamily(tripID);
                } else if (tm.isFriendOf(tripID, user.username)) {
                    containerIDs = ccm.getAllContentContainersOfTripForFriends(tripID);
                } else {
                    containerIDs = ccm.getAllContentContainersOfTripForEverybody(tripID);
                }
            } else {
                containerIDs = ccm.getAllContentContainersOfTripForEverybody(tripID);
            }
            result = new ContainerObject[containerIDs.length];
            for (int i = 0; i < containerIDs.length; i++) {
                result[i] = ccm.getContainerLocation(containerIDs[i]);
            }

            return result;
        } else {
            return null;
        }
    }
}
